//
//  SaveManager.m
//  LocomotiveGuards
//
//  Created by SmileFish on 16/6/30.
//  Copyright © 2016年 REDOOR. All rights reserved.
//

#import "SaveManager.h"

static SaveManager *manager = nil;
@implementation SaveManager

+ (SaveManager *)sharedSaveManager {
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[SaveManager alloc]init];
    });
    return manager;
}

+ (NSString *)getFilePathWithFileName:(NSString *)name {
    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject];
    NSString *newString = [documentPath stringByAppendingPathComponent:name];
    return newString;
    
}

// 存储
- (void)saveDataWithArray:(NSMutableArray *)array {
    // 1、得到路径
    NSString *newFilePath = [SaveManager getFilePathWithFileName:@"saveData.txt"];

    // 2、数组写入文件
    [array writeToFile:newFilePath atomically:YES];
    NSLog(@"%@",newFilePath);
}

// 读取
+ (NSMutableArray *)readData {
    // 找到路径
    NSString *newFile = [SaveManager getFilePathWithFileName:@"saveData.txt"];
    // 通过路径获取数组
    NSMutableArray *tempArray = [NSMutableArray arrayWithContentsOfFile:newFile];
    NSLog(@"%@",newFile);
    return tempArray;
}


@end
